home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 297_01 / exampl13.spr < prev    next >
Text File  |  1989-09-09  |  1KB  |  69 lines

  1. /* exampl13.spr */
  2. /*
  3.  Simple parsing of simple sentences
  4.  
  5. We assume the following grammar:
  6. sentence->subject predicate
  7. subject->article adjective noun
  8. subject->article noun
  9. subject-> name
  10. predicate-> intransitive_verb
  11. predicate-> transitive_verb subject
  12.  
  13. terminals:
  14. name->[edmund]
  15. name->[ronald]
  16. noun->[tree]
  17. intransitive_verb->[sleeps]
  18. transitive_verb->[likes]
  19. article->[the]
  20. article->[a]
  21. adjective->[big]
  22.  
  23. See Clocksin and Mellish for a discussion.
  24. */
  25.  
  26. ((parse Input_sentence_list Output_parse)
  27.     (sentence Output_parse Input_sentence_list ())
  28. )
  29.  
  30. ((sentence ((subject S)(predicate P)) Linput Remaining)    
  31.  (subject S Linput L1)
  32.  (predicate P L1 Remaining)
  33. )
  34. ((subject ((article A)(adjective Adj)(noun N)) L R)
  35.  (article A L L1)
  36.  (adjective Adj L1 L2)
  37.  (noun N L2 R)
  38. )
  39. ((subject ((article A)(noun N)) L R)
  40.  (article A L L1)
  41.  (noun N L1 R)
  42. )
  43. ((subject ((name N)) L R)
  44.  (name N L R)
  45. )
  46. ((predicate ((intransitive_verb V)) L R)
  47.  (intransitive_verb V L R)
  48. )
  49. ((predicate ((transitive_verb V)(subject S)) L R)
  50.  (transitive_verb V L L1)
  51.  (subject S L1 R)
  52. )
  53. (article the (the | L) L)
  54. (article a (a | L) L)
  55. (name edmund (edmund | L)L)
  56. (name ronald (ronald | L)L)
  57. (adjective big (big | L) L)
  58. (intransitive_verb sleeps (sleeps | L) L)
  59. (transitive_verb likes (likes |L)L)
  60. (noun tree (tree | L) L)
  61.  
  62. /* try ?-(example13) */
  63. ((example13)
  64.  (parse (the big tree likes edmund) P)
  65.  (display P)
  66.  (nl)
  67.  (cut)
  68. )
  69.